package com.miao.im.api;

import com.miao.im.common.ApiResult;
import com.miao.im.service.message.IMessageManager;
import com.miao.im.service.message.OfflineMessageCounter;
import com.miao.im.support.WebSessionHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Auther: miaoguoxin
 * @Date: 2021/4/24 20:22
 * @Description:
 */
@RestController()
@RequestMapping("message")
public class MessageController {

    @Autowired
    private IMessageManager messageManager;

    /**
     * @Description: 获取离线消息计数器
     * @Author: miaoguoxin
     * @Date: 2021/4/24
     */
    @GetMapping("/offline_msg_counter")
    public ApiResult<Map<String, OfflineMessageCounter>> getOfflineMsgCounter() {
        Long userId = WebSessionHolder.getUserIdNotNull();
        Map<String, OfflineMessageCounter> offlineMsgCounter = messageManager.getOfflineMsgCounter(userId);
        return ApiResult.ok(offlineMsgCounter);
    }

    /**
     * @Description: 删除离线消息计数器
     * @Author: miaoguoxin
     * @Date: 2021/4/24
     */
    @DeleteMapping("/offline_msg_counter")
    public ApiResult<?> delOfflineMsgCounter() {
        Long userId = WebSessionHolder.getUserIdNotNull();
        messageManager.delOfflineCounter(userId);
        return ApiResult.ok(null);
    }
}
